package org.unt.logic;

import java.util.ArrayList;
import java.util.List;

import org.apache.log4j.Logger;

public class Strings {

	private static Logger logger = Logger.getLogger("Strings");

	public static void main(String[] args) {
		// List<String> list = getAllOcurrences("ads href='./css/print.css' adsf href=./css/abccss\" ", "href=");
		// for (String str : list)
		// System.out.println(str);
	}


	/**
	 * From "ads href='./css/print.css' adsf href=\"./css/abccss\" ", it gets ./css/print.css & ./css/abccss
	 * 
	 * @param str
	 * @param token
	 * @return
	 */
	public static List<String> getAllOcurrences(String str, String token) {

		List<String> list = new ArrayList<String>();

		while (str.indexOf(token) > -1) {

			try {
				int index = str.indexOf(token) + token.length();
				String separator = str.substring(index, index + 1);
				str = str.substring(index + 1);
				list.add(str.substring(0, str.indexOf(separator)));
			} catch (StringIndexOutOfBoundsException e) {
				logger.error("StringIndexOutOfBoundsException");
				logger.error(str);
				logger.error(e);
			}
		}

		return list;
	}
}
